<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 17-11-1
 * Time: 上午10:09
 */

namespace wodrow\models;

use ActiveRecord\Model;
use wodrow\tools\Db;
use wodrow\tools\Tools;

/**
 * This is the model class for table "dyhl_order_oldinfo".
 *
 * @property integer $o_id
 * @property string $o_number
 * @property string $o_status
 * @property string $o_vip_name
 * @property string $o_car_plate
 * @property integer $o_app_id
 * @property string $o_app_status
 * @property string $o_branch
 * @property integer $o_branch_id
 * @property string $o_branch_type
 * @property integer $o_uid
 * @property string $o_uname
 * @property string $o_add_time
 * @property string $o_sell_time
 * @property string $o_first_time
 * @property string $o_first_atime
 * @property string $o_finishe_time
 * @property integer $o_bank_id
 * @property string $o_bank
 * @property string $o_bankrate_time
 * @property string $o_bank_rate
 * @property string $o_loan_money
 * @property string $o_gps_no
 * @property string $o_gps_status
 * @property string $o_car_pose
 * @property string $o_2check_date
 * @property string $o_carcard_img
 * @property string $o_ad_money
 * @property integer $o_adtime
 * @property integer $o_pact_totime
 * @property integer $o_lrid
 */
class OrderOldinfo extends Model
{
    public static $table_name = "dyhl_order_oldinfo";

    public function yii__attributeLabels()
    {
        return array(
            'o_id' => 'FCustID',
            'o_number' => '订单号',
            'o_status' => '状态',
            'o_vip_name' => '客户名称',
            'o_car_plate' => 'O Car Plate',
            'o_app_id' => 'ID',
            'o_app_status' => '状态',
            'o_branch' => '部门',
            'o_branch_id' => '部门ID',
            'o_branch_type' => '部门ID dot 网点 dp 部门 rg大区',
            'o_uid' => '信贷专员ID',
            'o_uname' => '信贷专员',
            'o_add_time' => 'O Add Time',
            'o_sell_time' => 'O Sell Time',
            'o_first_time' => 'O First Time',
            'o_first_atime' => 'O First Atime',
            'o_finishe_time' => 'O Finishe Time',
            'o_bank_id' => '银行ID',
            'o_bank' => '银行',
            'o_bankrate_time' => 'O Bankrate Time',
            'o_bank_rate' => 'O Bank Rate',
            'o_loan_money' => 'O Loan Money',
            'o_gps_no' => 'O Gps No',
            'o_gps_status' => 'O Gps Status',
            'o_car_pose' => 'O Car Pose',
            'o_2check_date' => 'O 2check Date',
            'o_carcard_img' => 'O Carcard Img',
            'o_ad_money' => 'O Ad Money',
            'o_adtime' => 'O Adtime',
            'o_pact_totime' => 'O Pact Totime',
            'o_lrid' => 'ID',
        );
    }

    /**
     * @param $where
     * @return self
     */
    public static function findOne($where)
    {
        $models = self::find('all', array('conditions' =>Db::getConditions($where)));
        if (count($models)>1){
            throw new \ErrorException('一对一不能有多个');
        }
        /**
         * @var self $model
         */
        $model = $models[0];
        return $model;
    }

    /**
     * @return Order
     */
    public function getOrder()
    {
        /**
         * @var Order $order
         */
        $order = Order::findOne(array(array('=', 'o_id', $this->o_app_id)));
        return $order;
    }
}